<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Category;
use App\Models\Post;

class NewsController extends Controller
{
    public function index($slug)
    {
        $cat = Category::where('name', '=', $slug)->get(['id']);
        foreach ($cat as $key => $value) {
            $catId = $value->id;
        }
        $post = Post::where('cate_id', $catId)->get();
    	return view('news.index', ['post' => $post]);
    }

    public function new($id) {
        $new = Post::find($id);
        return view('news.new', [ 'new' => $new]);
    }

    public function notice($id)
    {
        $notice = Post::find($id);
        return view('news.notice',['notice' => $notice]);
    }
}
